# Maintainer: Leon White <badfunkstripe@gmail.com>
pkgname=bazel6
pkgver=6.5.0
pkgrel=0
pkgdesc="Bazel is an open-source build and test tool"
url="https://bazel.build/"
arch="all !x86 !armhf !armv7 !riscv64 !s390x !aarch64 !ppc64le !loongarch64"
license="Apache-2.0"
depends="bash openjdk11-jdk"
makedepends="linux-headers python3 unzip zip"
# Bazel binary is thin C++ client with zip file embedded into the binary,
# stripping breaks that: https://github.com/bazelbuild/bazel/issues/11842
options="!strip"
provides="bazel=$pkgver-r$pkgrel"
subpackages="$pkgname-bash-completion"
source="https://github.com/bazelbuild/bazel/releases/download/$pkgver/bazel-$pkgver-dist.zip
	0001-Do-not-use-prebuilt-binaries.patch
	0002-Prefer-local_jdk-instead-of-remote_jdk11.patch
	0003-Make-generate_bash_completion-compatible-with-busybo.patch
	0004-Use-nojdk-bazel-for-generating-the-bash-completion.patch
	0005-cstdint.patch
	"
builddir="$srcdir/"

build() {
	EMBED_LABEL=$pkgver-$pkgrel \
	EXTRA_BAZEL_ARGS=--tool_java_runtime_version=local_jdk \
		./compile.sh

	./output/bazel build --host_copt=-D_LARGEFILE64_SOURCE //scripts:bazel-complete.bash
	cp bazel-bin/scripts/bazel-complete.bash output/

	./output/bazel clean --expunge
}

check() {
	# shellcheck disable=SC2046
	./output/bazel build --host_copt=-D_LARGEFILE64_SOURCE $(\
		./output/bazel query --noshow_progress '//examples/...' \
			| grep -vF \
				-e /android/ \
				-e /windows/ \
				-e :hello-error-prone \
	)
	./output/bazel test --host_copt=-D_LARGEFILE64_SOURCE --test_output=errors \
		//examples/cpp:hello-success_test \
		//examples/java-native/src/test/java/com/example/myproject:custom \
		//examples/java-native/src/test/java/com/example/myproject:hello \
		//examples/java-starlark/src/test/java/com/example/myproject:pass \
		//examples/py_native:test \
		//examples/shell:test

	./output/bazel clean --expunge
}

package() {
	install -Dm 755 -t "$pkgdir/usr/bin" output/bazel
	install -Dm 644 output/bazel-complete.bash \
		"$pkgdir/usr/share/bash-completion/completions/bazel"
}

sha512sums="
c12f3072de3643f2c1754781ef737b85c05fbb39a77f87f0d4230068c519cb352607c42eb8abcad58c736c1d396bc7e7f879f04cbad0ce9e845a3621401451be  bazel-6.5.0-dist.zip
2d95a96645929211c1f4d997d4dfc70c96506cd3f86851a1735224f84aa272bcab0445f30a3834cf3e62a6682ba96195e4f69304a526ffe62c4c8db6f6013846  0001-Do-not-use-prebuilt-binaries.patch
d189d7dc6a46aca4fba5f3d3652bd91589f833772ab480aee3e68390d6f5f7f37a3f528be0a0ebce20ec4dfabbf3c7f856220afa1810627643df4e34533b5abf  0002-Prefer-local_jdk-instead-of-remote_jdk11.patch
b0bae27087f8d1da6a455500fc9fb4758ffdeaa27f0b11de720a0607aa3a4d682adfc1286b6385fe53e67296e7af1f61570b6b3093def1e8cee8531c7f4f5f82  0003-Make-generate_bash_completion-compatible-with-busybo.patch
a102371e03345e62e3ecc181382481563be92246bda08d9a6c24964c35d07301a20ecc32d519a9c9d9a6d0827b6773357f9ac756fa01ae685666100f0413d09b  0004-Use-nojdk-bazel-for-generating-the-bash-completion.patch
4e8bd5986b689948f01496af3f1b9d1afb0e2da53f0ddde921b028a2d309fec5c8ad209ad088823d164dce49fbb3a8aef7eea251ac2061639c74051089276314  0005-cstdint.patch
"
